import React from 'react';
import * as asyncLoad from '../util/asyncLoad';
import * as Util from '../util/formUtil';
import * as type from '../constants/type';
import { workflowPublicFiles } from '../constants/fileConfig';
import Loading from './Loading';
import { observer, inject } from "mobx-react/index";
import {toJS,observable,asMap} from 'mobx'

@inject("globalStore")
@observer
export default class FreeFlowSet extends React.Component {
    constructor() {
        super();
        this.state = { hasLoad: false };
    }
    componentDidMount() {
        const init = () => {
            const { WorkflowNewDesignStore } = window.weaWorkflowPublic;
            const store = new WorkflowNewDesignStore();
            this.setState({ hasLoad: true, store: store });
        }
        asyncLoad.asyncLoadModule('workflowPublic', workflowPublicFiles, init);
    }
    render() {
        const { globalStore , openType} = this.props;
        const { hasLoad, store } = this.state;
        const { commonParam , rightMenu} = globalStore;
        const { requestid,workflowid,nodeid,iscreate,f_weaver_belongto_userid,f_weaver_belongto_usertype } = commonParam;
	    const { iscnodefree,isFree,freewftype,freeNode = {} ,isAllowNodeFreeFlow} = rightMenu;
	    let chartParams  = {requestid,workflowid,nodeid,isAllowNodeFreeFlow,isFree,'isFlowModel':0,'isReadOnlyModel':false};
        const picUrl = `/workflow/workflowDesign/readOnly-index.html?${this.buildUrlStr(chartParams)}&showE9Pic=1&isFromWfForm=true`;
        
        if (hasLoad) {
            const { FreeFlowDesignContainer } = window.weaWorkflowPublic;
            if(openType === 'modelset'){
                return (<FreeFlowDesignContainer ecId={`${this && this.props && this.props.ecId || ''}_FreeFlowDesignContainer@9p5k27`}
                        workflowNewDesignStore={store}
                        {...chartParams}
                        {...this.props}
                    />);
            }else{
                return (<div className='free-designer-frame' style={{height:'100%'}}>
                        <iframe src={picUrl} style={{width:'100%',height:'100%'}}></iframe>
                    </div>);
            }
        } else {
            return (<Loading ecId={`${this && this.props && this.props.ecId || ''}_Loading@i6l1th`} />);
        }
    }
    //拼接url链接
    buildUrlStr = (params = {}) => {
        let str = "";
        _.forIn(params, (value, key) => {
            str += `&${key}=${value}`;
        });
        if (str !== "")
            str = str.substring(1);
        return str;
    }
}